package com.yq.ylmall.product.controller.admin;

import com.yq.ylmall.product.service.IRegionService;
import com.yq.ylmall.result.Result;
import com.yq.ylmall.result.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 地区 后台前端控制器
 * </p>
 *
 * @author lsx
 * @since 2024-6-11
 */
@Api(tags = "地区管理接口")
@RestController
@RequestMapping("/admin/product/region")
@RequiredArgsConstructor
public class RegionAdminController {
    private final IRegionService regionService;
    @ApiOperation(value = "获取全部地区")
    @GetMapping("/list")
    public Result<String> list(){
        return Result.ok(regionService.findAll());
    }

    @ApiOperation(value = "导出为excel")
    @GetMapping(value = "/export-data")
    public void exportData(HttpServletResponse response){regionService.exportData(response);}

    @ApiOperation(value = "excel导入")
    @PostMapping("/importData")
    public Result<Object> importData(MultipartFile file){
        regionService.importData(file);
        return Result.ok(ResultCode.SUCCESS);
    }

}
